package com.ruoyi.stock.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.SecurityUtils;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.stock.domain.StockUserHeaderSettting;
import com.ruoyi.stock.service.IStockUserHeaderSetttingService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 头设置
Controller
 * 
 * @author ruoyi
 * @date 2025-01-07
 */
@RestController
@RequestMapping("/stock/settting")
@Api( tags = "个人表头设置")
public class StockUserHeaderSetttingController extends BaseController
{
    @Autowired
    private IStockUserHeaderSetttingService stockUserHeaderSetttingService;

    /**
     * 查询头设置
列表
     */
    @GetMapping("/list")
    public TableDataInfo list(StockUserHeaderSettting stockUserHeaderSettting)
    {
        startPage();
        List<StockUserHeaderSettting> list = stockUserHeaderSetttingService.selectStockUserHeaderSetttingList(stockUserHeaderSettting);
        return getDataTable(list);
    }

    /**
     * 导出头设置
列表
     */
    @Log(title = "头设置 ", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, StockUserHeaderSettting stockUserHeaderSettting)
    {
        List<StockUserHeaderSettting> list = stockUserHeaderSetttingService.selectStockUserHeaderSetttingList(stockUserHeaderSettting);
        ExcelUtil<StockUserHeaderSettting> util = new ExcelUtil<StockUserHeaderSettting>(StockUserHeaderSettting.class);
        util.exportExcel(response, list, "头设置 数据");
    }

    /**
     * 获取头设置
详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(stockUserHeaderSetttingService.selectStockUserHeaderSetttingById(id));
    }


    /**
     * 新增头设置

     */
    @Log(title = "头设置 ", businessType = BusinessType.INSERT)
    @ApiOperation(value = "表头设置保存")
    @PostMapping(value="psersonadd")
    public AjaxResult psersonadd(@RequestBody StockUserHeaderSettting stockUserHeaderSettting)
    {
        stockUserHeaderSetttingService.deleteStockUserHeaderSetttingByUserId(SecurityUtils.getUserId());
        List<Long> list=  stockUserHeaderSettting.getHeaderSettingIds();
        if(list!=null){
            for(int i=0; i<list.size();i++){
                StockUserHeaderSettting stockUserHeaderSettting1=new StockUserHeaderSettting();
                stockUserHeaderSettting1.setHeaderSettingId(list.get(i)+"");
                stockUserHeaderSettting1.setSysUserId(SecurityUtils.getUserId());
                stockUserHeaderSetttingService.insertStockUserHeaderSettting(stockUserHeaderSettting1);
            }
        }
        return toAjax(list==null?0:list.size());
    }


    /**
     * 新增头设置

     */
    @Log(title = "头设置 ", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody StockUserHeaderSettting stockUserHeaderSettting)
    {
        return toAjax(stockUserHeaderSetttingService.insertStockUserHeaderSettting(stockUserHeaderSettting));
    }

    /**
     * 修改头设置

     */
    @Log(title = "头设置 ", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody StockUserHeaderSettting stockUserHeaderSettting)
    {
        return toAjax(stockUserHeaderSetttingService.updateStockUserHeaderSettting(stockUserHeaderSettting));
    }

    /**
     * 删除头设置
     */
    @Log(title = "头设置 ", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(stockUserHeaderSetttingService.deleteStockUserHeaderSetttingByIds(ids));
    }
}
